<template>
  <div class="slider">
    <swiper :options="swiperOption">
      <slot></slot>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>
<script>
export default {
  name: 'slider',
  props: {
    loop: {
      type: Boolean,
      default: false
    },
    direction: {
      type: String,
      validator (value) {
        return ['horizontal', 'vertical'].indexOf(value) > -1
      },
      default: 'horizontal'
    },
    autoplay: {
      type: Number,
      default: 0
    },
    speed: {
      type: Number,
      default: 300
    },
    pagination: {
      type: Boolean,
      default: true
    },
    paginationType: String
  },
  created () {
    this.swiperOption = {
      loop: this.loop,
      direction: this.direction,
      autoplay: this.autoplay,
      speed: this.speed,
      // observeParents: true,
      // observer: true,
      pagination: {
        el: this.pagination ? '.swiper-pagination' : null,
        type: this.paginationType ? this.paginationType : 'bullets'
      },
      observeParents: true, // 父组件发生变化要更新一下
      observer: true // 自身发生变化要更新一下
    }
  }
}
</script>
<style lang="stylus" scoped>
.slider
  width 100%

</style>
